<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Api\Controller;
use Think\Controller;

/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用分组名称
 */
class TooController extends Controller {

	/* 空操作，用于输出404页面 */
	// public function _empty(){
	// 	echo 404; //TODO:完成404页面
	// }
	// TODO: 为了调试方便，暂时注释

    protected function _initialize(){
        /* 读取站点配置 */
        $config = api('Config/lists');
        C($config); //添加配置

        if(!C('WEB_SITE_CLOSE')){
            $this->error('站点已经关闭，请稍后访问~');
        }

        //自动登陆
        if(empty(session('member'))){
            if($_COOKIE['member_id']){
                $arr=M('tmember')->where(array('id'=>$_COOKIE['member_id']))->find();
                session('member',$arr); //存入session
                setcookie('member_id',$arr['id'],time()+7*24*60*60,'/');
            }else{
                //判断是否登陆
                $this->redirect('Login/login');
            }
        }

    }


    public function TBD_upload($file){
        //TODO: 用户登录检测

        /* 返回标准数据 */
       // $return  = array('status' => 1, 'info' => '上传成功', 'data' => '失败');

        /* 调用文件上传组件上传文件 */

        if($file['error']==0){
            $path="/Uploads/Download/".date('Y-m-d');
            if(!is_dir($_SERVER['DOCUMENT_ROOT'].$path)){

                mkdir($_SERVER['DOCUMENT_ROOT'].$path);
            }

            $hz=explode('/',$file['type']);
            $hz='.'.array_pop($hz);
            $name=$path.'/'.time().rand(1000,9999).$hz;
//            $name=$path.'/'.$file['name'];
            if(move_uploaded_file($file['tmp_name'],$_SERVER['DOCUMENT_ROOT'].$name)){
//                $return['data']=$name;
                return $name;
               //return json_encode($return);
            }
        }
        return false;
//        return json_encode($return);
    }
}
